package com.ruoyi.web.controller.scbz;

import java.util.Scanner;
import java.time.LocalDateTime;
public class BaziCalculator {
    // 天干地支定义
    private static final String[] GAN = {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
    private static final String[] ZHI = {"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入出生年份(如1990):");
        int year = scanner.nextInt();
        System.out.println("请输入出生月份(1-12):");
        int month = scanner.nextInt();
        System.out.println("请输入出生日期(1-31):");
        int day = scanner.nextInt();
        System.out.println("请输入出生时辰(0-23):");
        int hour = scanner.nextInt();

        // 计算年柱
        int ganIndex = (year - 4) % 10;
        int zhiIndex = (year - 4) % 12;
        String yearGanZhi = GAN[ganIndex] + ZHI[zhiIndex];

        // 计算月柱（简化版，实际需考虑节气）
        int monthZhiIndex = (month + 1) % 12;
        String monthGanZhi = GAN[(ganIndex * 2 + month) % 10] + ZHI[monthZhiIndex];

        // 计算日柱（简化版，实际需复杂公式）
        LocalDateTime date = LocalDateTime.of(year, month, day, 0, 0);
        int dayIndex = (int)(date.toLocalDate().toEpochDay() + 10) % 60;
        String dayGanZhi = GAN[dayIndex % 10] + ZHI[dayIndex % 12];

        // 计算时柱
        int hourZhiIndex = (hour + 1) / 2 % 12;
        String hourGanZhi = GAN[(dayIndex % 10 * 2 + hourZhiIndex) % 10] + ZHI[hourZhiIndex];

        System.out.println("您的生辰八字为：");
        System.out.println("年柱：" + yearGanZhi);
        System.out.println("月柱：" + monthGanZhi);
        System.out.println("日柱：" + dayGanZhi);
        System.out.println("时柱：" + hourGanZhi);
    }
}
